﻿using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
using UnityEngine.UI;

namespace ZXthex.EditorUI
{
    public class EditorInputField : EditorRectTransform
    {
        public EditorInputField()
        {
        }

        public InputField.LineType lineType { get; set; }

        private InputField.ContentType m_contentType;
        public InputField.ContentType contentType
        {
            get
            {
                if (lineType == InputField.LineType.SingleLine)
                    return m_contentType;
                return InputField.ContentType.Standard;
            }
            set
            {
                m_contentType = value;
                if (contentType != InputField.ContentType.Standard)
                {
                    lineType = InputField.LineType.SingleLine;
                }
            }
        }

        private int m_intText;
        private float m_floatText;
        private string m_text;
        public string text
        {
            get
            {
                if (contentType == InputField.ContentType.IntegerNumber)
                    return m_intText.ToString();
                else if (contentType == InputField.ContentType.DecimalNumber)
                    return m_floatText.ToString();
                return m_text;
            }
            set
            {
                contentType = InputField.ContentType.Standard;
                m_text = value;
            }
        }


        internal override void SelfGUI()
        {
            if (lineType == InputField.LineType.SingleLine)
            {
                if (contentType == InputField.ContentType.IntegerNumber)
                {
                    m_intText = EditorGUI.IntField(guiRect, m_intText);
                }
                else if(contentType == InputField.ContentType.DecimalNumber)
                {
                    m_floatText = EditorGUI.FloatField(guiRect, m_floatText);
                }
                else
                {
                    m_text = EditorGUI.TextField(guiRect, m_text);
                }
            }
            else
            {
                text = GUI.TextArea(guiRect, text);
            }
        }
    }
}